import Mock from 'mockjs'

Mock.mock('/tablelist', function (res) {
    let body = JSON.parse(res.body)
    let data = Mock.mock({
        "tableData|210": [{
            "name|5-6": "@cword",
            "price|200-400": 1,
            "describe|10-20": "@cword",
            "caketypeid|1-7": 1,
            "cakeflavorid|1-8": 1
        }]
    }).tableData
    console.log(body)
    // 根据两个id进行筛选
    if (body.caketypeid) {
        data = data.filter(item => item.caketypeid == body.caketypeid)
    }
    if (body.cakeflavorid) {
        data = data.filter(item => item.cakeflavorid == body.cakeflavorid)
    }
    // 在这里获取全部数据的长度
    let length = data.length
    // 根据传过来的页数进行切割
    let page = body.page
    data = data.slice((page - 1) * 20, page * 20)
    return {
        data,
        length
    }
})